package com.cheng.web.action.system;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.cheng.bos.actionUtils.ActionUtils;
import com.cheng.domain.system.Role;
import com.cheng.service.system.RoleService;
import com.opensymphony.xwork2.ActionContext;

@Namespace("/role")
@ParentPackage("json-default")
@Controller
@Scope("prototype")
public class RoleAction extends ActionUtils<Role> {
	
	@Autowired
	private RoleService roleService;
	
	@Action(value="role_query",results={@Result(name="success",type="json")})
	public String queryRole(){
		List<Role> list = roleService.findAll();
		ActionContext.getContext().getValueStack().push(list);
		return SUCCESS;
	}
	
	private String menuids;
	private Integer[] permissionIds;

	public void setMenuids(String menuids) {
		this.menuids = menuids;
	}

	public void setPermissionIds(Integer[] permissionIds) {
		this.permissionIds = permissionIds;
	}

	@Action(value="role_save",results={@Result(name="success",type="redirect",location="../pages/system/role.html")})
	public String saveRole(){
		roleService.saveRole(model,permissionIds,menuids);
		return SUCCESS;
	}
}
